package com.pac.questionnaire.service.impl;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.common.tools.StringTools;
import com.common.util.ErrorNumber;
import com.common.util.LogicException;
import com.pac.questionnaire.bean.QuestionOptionBean;
import com.pac.questionnaire.dao.QuestionOptionDao;
import com.pac.questionnaire.service.QuestionOptionService;

/**
 * 问题选项service实现
 * 
 * @author lujun.chen
 * @version [版本号, 2015年2月24日]
 * @see [相关类/方法]
 * @since [产品/模块版本]
 */
@Service(value = "questionOptionService")
public class QuestionOptionServiceImpl implements QuestionOptionService {

	private static Logger logger = Logger
			.getLogger(QuestionOptionServiceImpl.class);

	@Autowired
	private QuestionOptionDao questionOptionDao;

	@Override
	@Transactional(propagation = Propagation.REQUIRED)
	public String addQuestionOption(QuestionOptionBean questionOptionBean) {
		if (null == questionOptionBean) {
			logger.error("添加问题选项出错，参数为空");
			throw new LogicException(ErrorNumber.PARAM_IS_NULL, "参数为空");
		}

		if (StringTools.isNull(questionOptionBean.getDescription())) {
			logger.error("添加问题选项出错，问题选项描述为空");
			throw new LogicException(ErrorNumber.PARAM_IS_NULL, "问题选项描述为空");
		}

		if (StringTools.isNull(questionOptionBean.getQuestionId())) {
			logger.error("添加问题选项描述出错，问题ID为空");
			throw new LogicException(ErrorNumber.PARAM_IS_NULL, "问题ID为空");
		}
		return questionOptionDao.addQuestionOption(questionOptionBean);
	}

	@Override
	@Transactional(propagation = Propagation.REQUIRED)
	public boolean updateQuestionOption(QuestionOptionBean questionOptionBean) {
		if (null == questionOptionBean) {
			logger.error("修改问题选项出错，参数为空");
			throw new LogicException(ErrorNumber.PARAM_IS_NULL, "参数为空");
		}

		if (StringTools.isNull(questionOptionBean.getId())) {
			logger.error("修改问题选项出错，问题选项ID为空");
			throw new LogicException(ErrorNumber.PARAM_IS_NULL, "问题选项ID为空");
		}
		return questionOptionDao.updateQuestionOption(questionOptionBean);
	}

	@Override
	@Transactional(propagation = Propagation.REQUIRED)
	public boolean delQuestionOption(QuestionOptionBean questionOptionBean) {
		if (null == questionOptionBean) {
			logger.error("删除问题选项出错，参数为空");
			throw new LogicException(ErrorNumber.PARAM_IS_NULL, "参数为空");
		}

		if (StringTools.isNull(questionOptionBean.getQuestionId())) {
			logger.error("删除问题选项出错，问题ID为空");
			throw new LogicException(ErrorNumber.PARAM_IS_NULL, "问题ID为空");
		}
		return questionOptionDao.delQuestionOption(questionOptionBean);
	}

	@Override
	public List<QuestionOptionBean> queryQuestionOption(
			QuestionOptionBean questionOptionBean) {
		return questionOptionDao.queryQuestionOption(questionOptionBean);
	}

}
